package com.wg.io.sqlSession;

import com.wg.io.config.XMLConfigerBuilder;
import com.wg.io.pojo.Configuration;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

/**
 * @author Mrwg
 * @date 2020/3/26 11:58
 * @description
 */
public class SqlSessionFactoryBuilder {
    private Configuration configuration;

    public SqlSessionFactoryBuilder() {
        this.configuration = new Configuration();
    }

    public SqlSessionFactory bulid(InputStream in) throws DocumentException, PropertyVetoException, ClassNotFoundException {
        //1、使用dom4j 解析配置文件 configuration
        XMLConfigerBuilder xmlConfigerBuilder = new XMLConfigerBuilder(configuration);
        Configuration configuration = xmlConfigerBuilder.parseConfiguration(in);

        //2、创建SqlSessionFactory 对象生产seqSession
        DefaultSqlSessionFactory defaultSqlSessionFactory = new DefaultSqlSessionFactory(configuration);
        return  defaultSqlSessionFactory;
    }
}
